<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %><!-- 数据库操作需要 -->        
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%

		//获取参数，转换为相应的类型		 
		try {
			Class.forName("org.h2.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return;
		}
		String url="jdbc:h2:d:/CompanyCar/temp/mydbtest";
		Connection conn=null;
		System.out.println("1");
		//数据库连接与查询过程中可能会引发sql异常
		try {
			//获取数据库连接(url,username,password)			
			conn = DriverManager.getConnection(url,"sa","");
			//准备执行数据库查询
			String EmpID=request.getParameter("EmpID");
			request.setAttribute("EmpID",EmpID);
			String Name=request.getParameter("Name");
			System.out.println(EmpID);
			System.out.println(Name);
			String sql="";
			sql="update Employee set Name =?,Gender=?,Age=?,IDNumber=?,Phone=?,Address=?,Department=?,Rank=?,Position=?,Hometown=?,Education=?,YearsOfWorking=?,HireDate=?,MaritalStatus=?,Birthplace=?,Birthday=?,EthnicGroup=?  where EmpID ='"+EmpID+"'";
			PreparedStatement stmt=conn.prepareStatement(sql);
			stmt.setString(1, request.getParameter("Name"));
			stmt.setString(2, request.getParameter("Gender"));
			stmt.setString(3, request.getParameter("Age"));
			stmt.setString(4, request.getParameter("IDNumber"));
			stmt.setString(5, request.getParameter("Phone"));
			stmt.setString(6, request.getParameter("Address"));
			stmt.setString(7, request.getParameter("Department"));
			stmt.setString(8, request.getParameter("Rank"));
			stmt.setString(9, request.getParameter("Position"));
			stmt.setString(10, request.getParameter("Hometown"));
			stmt.setString(11, request.getParameter("Education"));
			stmt.setString(12, request.getParameter("YearsOfWorking"));
			stmt.setString(13, request.getParameter("HireDate"));
			stmt.setString(14, request.getParameter("MaritalStatus"));
			stmt.setString(15, request.getParameter("Birthplace"));
			stmt.setString(16, request.getParameter("Birthday"));
			stmt.setString(17, request.getParameter("EthnicGroup"));
			//循环获取结果集当中的所有数据
			int result=stmt.executeUpdate();
			System.out.println(result);
			//关闭表达式对象
			stmt.close();			
			//关闭数据库			
			conn.close();			
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			//防止数据库未正常关闭
			try{
				if (conn!=null && (!conn.isClosed())){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}		request.getRequestDispatcher("/X-UseCar_PersonalInformation.jsp").forward(request, response);
		// 转发到JSP页面	
%>		
<script>

</script>
		


</body>
</html>